<template>
	<view class="container">

		<view class="avatar" v-if="soure == 'hire' || soure == 'clear' || soure == 'product'">
			<!-- 上传组件 -->
			<u-upload ref="product_img" name="product_img" maxCount="6" :fileList="filelist" width="100" height="100" />
		</view>

		<view class="content" v-if="soure == 'hire'">
			<u-form labelPosition="left" labelWidth="60" :model="prolist">
				<u-form-item label="平台客户:">
					<u-input v-model="order.business.nickname" disabled />
				</u-form-item>
				<!-- 订单号 -->
				<u-form-item label="订单号:">
					<u--input v-model="order.code" />
				</u-form-item>
				<!-- 联系人 -->
				<u-form-item label="联系电话:">
					<u--input disabled type="number" v-model="order.business.mobile" />
				</u-form-item>
				<!-- 名称 -->
				<!-- <u-form-item label="待洗车辆:">
					<u-input v-model="order.carpark.carnumberplate" disabled />
				</u-form-item> -->
				<u-form-item label="租车门店:">
					<u-input v-model="order.storename_text" disabled />
				</u-form-item>

				<!-- 品牌 -->
				<u-form-item label="品牌" prop="brank">
					<u-input v-model="order.hire.brankname_text" disabled />
				</u-form-item>
				<u-form-item label="系列" prop="name">
					<u-input v-model="order.hire.btypename_text" disabled />
				</u-form-item>
				<u-form-item label="租车名称" prop="name">
					<u-input v-model="order.hire.name" disabled />
				</u-form-item>
				<u-form-item label="租金" prop="amount">
					<u-input v-model="order.amount" disabled />
				</u-form-item>

				<!-- 参数1 -->
				<u-form-item label="订单状态:">
					<u-input v-model="order.status_text" disabled />
				</u-form-item>


				<u-form-item label="预约时间:">
					<u-input v-model="order.createtime_text" disabled />
				</u-form-item>



				<u-form-item label="保险:">
					<u-input v-model="order.insure_text" disabled />
				</u-form-item>
				<!-- <u-form-item label="员工提成:">
					<u-input v-model="order.hire.empcommission" disabled />
				</u-form-item> -->
				<!-- <u-form-item label="平台提成:" v-if="auth.id==1">
					<u-input v-model="order.hire.ptcommission" disabled />
				</u-form-item>
				<u-form-item label="客户提成:" v-if="auth.id==1">
					<u-input v-model="order.hire.buscommission" disabled />
				</u-form-item> -->



				<!-- 提交按钮 -->
				<u-button text="完成任务" v-if="order.status == 3" icon="pushpin" size="small" type="success"
					:customStyle="btnStyle" @click="complateConfirm" />
				<u-button text="接单" v-if="order.status == 10" icon="pushpin" size="small" type="primary"
					:customStyle="btnStyle" @click="receiveOrder" />
			</u-form>

		</view>
		<view class="content" v-if="soure == 'clear'">
			<u-form labelPosition="left" labelWidth="60" :model="prolist">
				<u-form-item label="平台客户:">
					<u-input v-model="order.business.nickname" disabled />
				</u-form-item>
				<!-- 订单号 -->
				<u-form-item label="订单号:">
					<u--input v-model="order.code" />
				</u-form-item>
				<!-- 联系人 -->
				<u-form-item label="联系电话:">
					<u--input disabled type="number" v-model="order.business.mobile" />
				</u-form-item>
				<!-- 名称 -->
				<u-form-item label="待洗车辆:">
					<u-input v-model="order.carnumberplate_text" disabled />
				</u-form-item>
				<u-form-item label="预约门店:">
					<u-input v-model="order.storename_text" disabled />
				</u-form-item>

				<!-- 参数1 -->
				<u-form-item label="订单状态:">
					<u-input v-model="order.status_text" disabled />
				</u-form-item>

				<u-form-item label="服务标题:">
					<u-input disabled v-model="order.title_text" />
				</u-form-item>
				<u-form-item label="订单类型:">
					<u-input disabled v-model="order.soure_text" />
				</u-form-item>

				<u-form-item label="洗车费:">
					<u-input disabled v-model="order.amount" />
				</u-form-item>

				<!-- 参数3 -->
				<u-form-item label="预约时间:">
					<u-input v-model="order.createtime_text" disabled />
				</u-form-item>
				<u-form-item label="保险:">
					<u-input v-model="order.insure_text" disabled />
				</u-form-item>


				<!-- 全款 -->
				<u-form-item label="服务费用:">
					<u-input disabled type="number" v-model="order.amount" />
				</u-form-item>
				<u-form-item label="员工提成:">
					<u-input disabled type="number" v-model="order.emptc_text" />
				</u-form-item>



				<!-- 提交按钮 -->
				<u-button text="完成任务" v-if="order.status == 3" icon="pushpin" size="small" type="success"
					:customStyle="btnStyle" @click="complateConfirm" />
				<u-button text="接单" v-if="order.status ==10" icon="pushpin" size="small" type="primary"
					:customStyle="btnStyle" @click="receiveOrder" />
			</u-form>

		</view>
		<view class="content" v-if="soure == 'product'">
			<u-form labelPosition="left" labelWidth="60" :model="prolist">
				<u-form-item label="平台客户:">
					<u-input v-model="order.business.nickname" disabled />
				</u-form-item>
				<!-- 订单号 -->
				<u-form-item label="订单号:">
					<u--input v-model="order.code" />
				</u-form-item>
				<!-- 联系人 -->
				<u-form-item label="联系电话:">
					<u--input disabled type="number" v-model="order.business.mobile" />
				</u-form-item>
				<!-- 名称 -->
				<u-form-item label="品牌系列:">
					<u-input v-model="order.cardname" disabled />
				</u-form-item>
				<u-form-item label="预约门店:">
					<u-input v-model="order.storename_text" disabled />
				</u-form-item>

				<!-- 参数1 -->
				<u-form-item label="订单状态:">
					<u-input v-model="order.status_text" disabled />
				</u-form-item>

				<u-form-item label="订单类型:">
					<u-input disabled v-model="order.soure_text" />
				</u-form-item>

				<u-form-item label="全款(w):">
					<u-input disabled v-model="order.product.price" />
				</u-form-item>
				<u-form-item label="首付(w):">
					<u-input disabled v-model="order.product.sf" />
				</u-form-item>

				<!-- 参数3 -->
				<u-form-item label="预约时间:">
					<u-input v-model="order.createtime_text" disabled />
				</u-form-item>
				<u-form-item label="保险:">
					<u-input v-model="order.insure_text" disabled />
				</u-form-item>


				<!-- 全款 -->
				<!-- <u-form-item label="服务费用:">
					<u-input disabled type="number" v-model="order.amount" />
				</u-form-item> -->

				<!-- <u-form-item label="员工提成:">
					<u-input disabled type="number" v-model="order.emptc_text" />
				</u-form-item> -->



				<!-- 提交按钮 -->
				<u-button text="完成任务" v-if="order.status == 3" icon="pushpin" size="small" type="success"
					:customStyle="btnStyle" @click="complateConfirm" />
				<u-button text="接单" v-if="order.status ==10" icon="pushpin" size="small" type="primary"
					:customStyle="btnStyle" @click="receiveOrder" />
			</u-form>

		</view>
		<!-- 消息提醒 -->
		<u-toast ref="notice"></u-toast>
		<u-modal :show="show" @confirm="receiveOrder" @cancel="cancel" @click="showbutton" showCancelButton title="是否确认接单"
			ref="uModal" :asyncClose="true"></u-modal>
	</view>
</template>
  
<script>
export default {
	onLoad(options) {

		this.orderid = options.orderid ? options.orderid : 0

		this.auth = this.$u.auth.check();
		
		this.info()

	},


	created() {

		this.timer = setInterval(() => {

			let a = this.$u.count.check()

		}, 15000);

	},
	beforeDestroy() {
		clearInterval(this.timer)
	},
	data() {
		return {
			orderid: 0,
			auth: {},
			soure: "",
			order: [],
			filelist: [],
			showbrank: false,
			param1: "",
			param2: "",
			param3: "",
			sf: 0,
			show: false,
			description: "",
			price: 0,



		};
	},

	methods: {
		showbutton() {
			this.show = false
		},
		cancel() {
			this.show = false
		},
		async receiveOrder() {

			this.show = false;
			let data = {
				status: 10,
				adminid: this.auth.id,
				orderid: this.orderid
			}

			let result = await this.$u.api.order.receive(data)

			if (result.code) {
				this.$refs.notice.show({
					type: "success",
					message: result.msg,
					duration: 1200,
				})
				setTimeout(() => {
					this.info(this.orderid)
				}, 1000)


			} else {
				this.$refs.notice.show({
					type: "error",
					message: result.msg,
					duration: 2000
				})
			}
		},
		async complateConfirm() {

			let data = {
				orderid: this.orderid,
				status: 10,
				adminid: this.auth.id
			}
			let result = await this.$u.api.order.complate(data)

			if (result.code) {
				this.$refs.notice.show({
					type: "success",
					message: result.msg,
					duration: 1000,
					complete: () => {
						//返回上一个界面
						uni.reLaunch({
							url: "/pagesB/order/index"
						})

					}
				});
			} else {
				this.$refs.notice.show({
					type: "danger",
					message: result.msg,
					duration: 2000,

				});
			}
		},
		async info() {
			let data = {
				orderid: this.orderid,
				adminid: this.auth.id
			}
			let result = await this.$u.api.order.OrderInfo(data)

			if (result.code) {
				this.order = result.data
				this.soure = result.data.soure
				if (this.soure == "hire") {


					// 租车图片整理
					if (this.order.hire.thumbs_text.length > 0) {


						this.filelist = this.order.hire.thumbs_text.map((item) => {
							return {
								url: item
							}
						});

						return false


					} else {

						this.filelist = []

					}

				} else if(this.soure == "product") {
					// 二手车图片
				
					if (this.order.product.thumbs_text.length > 0) {

						this.filelist = this.order.product.thumbs_text.map((item) => {
							return {
								url: item
							}
						});

						// console.log(this.filelist)
						return false



					} else {

						this.filelist = []

					}
				}else
				{
						if (this.order.carwash.image_text) {

						this.filelist = [{url:this.order.carwash.image_text}]
						

						// console.log(this.filelist)
						return false



					} else {

						this.filelist = []

					}
				}


			} else {
				this.$refs.notice.show({
					type: "danger",
					message: result.msg,
					duration: 2000
				})
			}
		}



	},
};
</script>
  
<style >
.content {
	padding: 20px;
}

.container {
	height: 100%;
	margin: 0 50rpx;
	box-sizing: border-box;
}

.avatar {
	text-align: center;
}

.u-avatar {
	margin: 80rpx auto 40rpx;
}

.xcx {
	width: 200rpx;
	height: 200rpx;
	margin: 80rpx auto 40rpx;
	border-radius: 100%;
	overflow: hidden;
}

.nickname {
	font-size: 14px;
	text-align: center;
}

.title {
	text-align: center;
	margin: 40rpx 0;
	font-size: 14rpx;
}

.avatar .u-upload {
	justify-content: center;
	align-items: center;
	margin: 3em auto;
}
</style>
  